/* Copyright 2009 Requirements Management System 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.mags.remas.model.entity.provider;

// Generated Jan 19, 2010 2:33:54 PM by Hibernate Tools 3.2.2.GA
// powered by MAGS

import java.io.Serializable;
import org.mags.dao.provider.CacheableDataProvider;
import org.mags.remas.model.entity.SystemProperty;

public class SystemPropertyProvider extends CacheableDataProvider <SystemProperty> {
	private static final long serialVersionUID = 1L;
	final private KeyTypeProvider keyTypeProvider;
	final private EnumNameProvider enumNameProvider;
	final private ListNameProvider listNameProvider; 

	public ListNameProvider getListNameProvider() {
		return listNameProvider;
	}
	public EnumNameProvider getEnumNameProvider() {
		return enumNameProvider;
	}
	public KeyTypeProvider getKeyTypeProvider() {
		return keyTypeProvider;
	}
	public SystemPropertyProvider(EnumNameProvider enumNameProvider
			, KeyTypeProvider keyTypeProvider, ListNameProvider listNameProvider) {
		this.enumNameProvider = enumNameProvider;
		this.keyTypeProvider = keyTypeProvider;
		this.listNameProvider = listNameProvider;
	}
	public SystemProperty getById(Serializable id) {
		for(SystemProperty i: this.getAll())
			if(i.getSystemPropertyId()==((Integer)id).intValue())
				return i;
		return null;
	}
	public SystemProperty getByName(String name) {
		for(SystemProperty i: this.getAll())
			if(i.getName().equalsIgnoreCase(name))
				return i;
		return null;
	}
	protected void loadProperties(SystemProperty one) {
		one.setKeyType(keyTypeProvider.getById(one.getKeyType().getKeyTypeId()));
		if(one.getEnumName()!=null)
			one.setEnumName(enumNameProvider.getById(one.getEnumName().getEnumNameId()));
		if(one.getListName()!=null)
			one.setListName(listNameProvider.getById(one.getListName().getListNameId()));
	}
}
